const router = require("koa-router")();
const { log } = require("console");

router.get("/news/:v/:id", (ctx) => {
  ctx.body = `你访问的的版本是${ctx.params.v}编号是${ctx.params.id}`;
})
  .get("/", async (ctx) => {
    ctx.body = "welcome home";
  })
  .get("/package/:id", async (ctx) => {
    ctx.body = `welcome ${JSON.stringify(ctx.params)}`;
  })
  .get("/users", async (ctx) => {
    console.log(ctx.query);
    console.log(ctx.querystring);
    console.log(ctx.url);
    console.log(ctx.request.query);
    console.log(ctx.request.querystring);
    // console.log(ctx.request);
    ctx.body = "this is newspages";
  })
  .post("/users", (ctx, next) => {
    //todo...
  })
  .put("/users/:id", (ctx, next) => {
    //todo...
  })
  .del("/users/:id", (ctx, next) => {
    //todo...
  })
  .all("/users/:id", (ctx, next) => {
    //todo...
  });
router.get("/hello/:name", async (ctx, next) => {
  var name = ctx.params.name;
  ctx.response.body = `<h1>Hello, ${name}!</h1>`;
});

module.exports=router;